package com.example.deeplearningjavafrombug.regex.lesson3;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Client {

    @Test
    public void test1() {
        List<String> data = new ArrayList<>();
        data.add("唱 跳 rap 篮球");
        data.add("唱,跳,rap,篮球");
        data.add("唱;跳;rap;篮球");
        for (String item : data) {
            String[] result = splitTabs(item);
            System.out.println(Arrays.toString(result));
        }
    }

    public static String[] splitTabs(String tabs) {
        if (tabs.split(",").length > 1) return tabs.split(",");
        if (tabs.split(";").length > 1) return tabs.split(";");
        if (tabs.split(" ").length > 1) return tabs.split(" ");
        return new String[0];
    }

    @Test
    public void test2() {
        List<String> data = new ArrayList<>();
        data.add("唱 跳 rap 篮球");
        data.add("唱,跳,rap,篮球");
        data.add("唱;跳;rap;篮球");
        for (String item : data) {
            String[] result = splitTabs2(item);
            System.out.println(Arrays.toString(result));
        }
    }

    public static String[] splitTabs2(String tabs) {
        return tabs.split("[,;\\s]");
    }

    @Test
    public void test3() {
        List<String> data = new ArrayList<>();
        data.add("唱,跳,rap,篮球");
        data.add("唱;跳;rap;篮球");
        data.add("唱 跳 rap 篮球");
        for (String item : data) {
            String result = uniformTabs(item);
            System.out.println(result);
        }
    }

    public static String uniformTabs(String tabs) {
        return tabs.replaceAll("[,;\\s]", ",");
    }

    @Test
    public void test4() {
        List<String> data = new ArrayList<>();
        data.add("唱,跳,rap,篮球");
        data.add("唱;跳;rap;篮球");
        data.add("唱 跳 rap 篮球");
        for (String item : data) {
            String result = replaceTabs(item);
            System.out.println(result);
        }
    }

    public static String replaceTabs(String tabs) {
        return tabs.replaceAll("([,;\\s])", "-->$1<--");
    }

    @Test
    public void test5() {
        String history = "【0.0.568】\n" +
                "修改内容：修复输入框缺少分隔符提示的 bug\n" +
                "【0.0.567】\n" +
                "修改内容：修复不知道什么时候引入的 bug\n" +
                "...\n" +
                "【0.0.003】\n" +
                "修改内容：修复修复第一个版本的 bug 时引入的 bug\n" +
                "【0.0.002】\n" +
                "修改内容：修复第一个版本的 bug\n" +
                "【0.0.001】\n" +
                "修改内容：第一个版本诞生！保证没有 bug！";
        String fixedHistory = fixHistory(history);
        System.out.println(fixedHistory);
    }

    private String fixHistory(String history) {
        return history.replaceAll("【\\d\\.\\d\\.(\\d)(\\d)(\\d)】", "【$1.$2.$3】");
    }


}
